import { TYPEORM_CONNECTIONS } from '@/database/typeorm/typeorm.constants';
import { Inject, OnApplicationShutdown } from '@nestjs/common';
import { DataSource } from 'typeorm';

export class UserService implements OnApplicationShutdown {
  constructor(
    @Inject(TYPEORM_CONNECTIONS) private connections: Map<string, DataSource>,
  ) {}
  onApplicationShutdown() {
    // 销毁数据库实例
    if (this.connections.size > 0) {
      for (const key of this.connections.keys()) {
        this.connections.get(key).destroy();
      }
    }
  }
}
